﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.Storage;
using Windows.Storage.Streams;
using Windows.UI.Popups;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=234238

namespace SplitViewOptions
{
    /// <summary>
    /// An empty page that can be used on its own or navigated to within a Frame.
    /// </summary>
    public sealed partial class textPlainRecievePage : Page
    {
        public textPlainRecievePage()
        {
            this.InitializeComponent();
        }
        protected override async void OnNavigatedTo(NavigationEventArgs e)
        {
            try
            {
                base.OnNavigatedTo(e);

                // Display the result of the file activation if we got here as a result of being activated for a file.
                var args = e.Parameter as FileActivatedEventArgs;

                if (args != null)
                {
                   
                    string output = "Files received: " + args.Files.Count + "\n";
                    //foreach (StorageFile file in args.Files)
                    //{
                    //    output = output + file.Name + "\n";
                    //
                    if (args.Files.Count > 0)
                    {
                       
                        StorageFile file = args.Files[0] as StorageFile;
                        if (file != null)
                        {
                            

                            string read = await FileIO.ReadTextAsync(file,UnicodeEncoding.Utf16BE);
                            Debug.WriteLine(read);
                            box.Text = read;
                            //if(read.Length<50)
                            // {
                            //     box.Text = read;
                            // }
                            //else
                            // {
                            //     box.Text = read.Substring(0, 39);
                            // }



                        }
                    }


                }
            }
            catch (Exception ex)
            {
                await App.showmessage(ex.Message);
                //MessageDialog one2311 = new MessageDialog(ex.Message);
                //await one2311.ShowAsync();
            }
            
                //rootPage.NotifyUser(output, NotifyType.StatusMessage);
          
        }

    }
}
